package com.springcloud.auth.authentication.controller;

import com.springcloud.auth.authentication.service.AuthenticationService;
import com.springcloud.common.core.entity.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * @author mori
 */
@RestController
@Slf4j
public class AuthenticationController {

    private AuthenticationService authenticationService;

    public AuthenticationController(AuthenticationService authenticationService) {
        this.authenticationService = authenticationService;
    }

    @PostMapping(value = "/auth/permission")
    public R<Boolean> decide(@RequestParam String url, @RequestParam String method, HttpServletRequest request) {
        boolean decide = authenticationService.decide(new HttpServletRequestAuthWrapper(request, url, method));
        return R.ok(decide);
    }

}
